package org.pub.lunch.google.map.view;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class RestaurantOverlay extends ItemizedOverlay<OverlayItem>
{
	private List<OverlayItem> items = new ArrayList<OverlayItem>();
	private Drawable marker = null;
	private Context context = null;	
	
	public RestaurantOverlay(Drawable defaultMarket, Context context,
			MyLocation myLoc, MyLocation resLoc)
	{
		super(defaultMarket);
		this.marker = defaultMarket;
		this.context = context;
				
		items.add(new OverlayItem(myLoc.getLocation(), "", myLoc.getName()));
		items.add(new OverlayItem(resLoc.getLocation(), "", resLoc.getName()));
		
		populate();
	}
	
	public RestaurantOverlay(Drawable marker, Context context, MyLocation location) {
		super(marker);
		this.marker = marker;
		this.context = context;
		items.add(new OverlayItem(location.getLocation(), "", location.getName()));
		
		populate();
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow)
	{
		super.draw(canvas, mapView, shadow);
		boundCenterBottom(marker);			
	}
	
	@Override
	protected boolean onTap(int i)
	{
		Toast.makeText(context, 
						items.get(i).getSnippet(),
						Toast.LENGTH_SHORT).show();
		return true;		
	}
	
	@Override
	protected OverlayItem createItem(int i)
	{	
		return items.get(i);
	}

	@Override
	public int size()
	{	
		return items.size();
	}

}
